from datetime import datetime

from exts import db
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, DecimalField, DateField
from wtforms.validators import DataRequired


class Usermodel(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.String(100), primary_key=True, nullable=False)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    department = db.Column(db.String(100), nullable=False)
    role = db.Column(db.String(100), nullable=False)
    number_of_times = db.Column(db.DECIMAL(3))
    phonenumber = db.Column(db.String(100))


class Whomodel(db.Model):
    __tablename__ = 'who'
    teacher_id = db.Column(db.String(100), primary_key=True, nullable=False)
    name = db.Column(db.String(100), nullable=False)
    department = db.Column(db.String(100), nullable=False)
    role = db.Column(db.String(100), nullable=False)
    number_of_times = db.Column(db.DECIMAL(3))
    phonenumber = db.Column(db.String(100))


class Statementmodel(db.Model):
    __tablename__ = 'cash_payment_instructions'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    jobnumber = db.Column(db.String(45), nullable=False)
    name = db.Column(db.String(45))
    amount = db.Column(db.DECIMAL(10, 2))
    reason = db.Column(db.String(100))
    inputer = db.Column(db.String(100))
    input_time = db.Column(db.DateTime)
    submitter = db.Column(db.String(45))
    submit_time = db.Column(db.DateTime)
    approver = db.Column(db.String(45))
    approve_time = db.Column(db.DateTime)
    status = db.Column(db.String(100))
    stage = db.Column(db.String(45))
    # 关系引用 #
    # users = db.relationship('Usermodel', backref='this_user')#


class Addstatementformmodel(FlaskForm):
    input_time = DateField('录入时间', default=datetime.today(), format='%d%m%Y%H%M', validators=[DataRequired()])
    jobnumber = StringField('工号', validators=[DataRequired()])
    who = StringField('姓名', validators=[DataRequired()])
    amount = DecimalField('金额', validators=[DataRequired()])
    reason = StringField('原因', validators=[DataRequired()])
    submit = SubmitField('提交')